﻿$(document).ready(function () {
	//breadcrumb
	$('#crumb-box-1').addClass('crumb-box-disable');
	$('#crumb-box-2').addClass('crumb-box-enable');
	$('#crumb-box-3').addClass('crumb-box-disable');

	$('#crumb-step-1').addClass('breadcrumb-menu-disable');
	$('#crumb-step-2').addClass('breadcrumb-menu-enable');
	$('#crumb-step-3').addClass('breadcrumb-menu-disable');
	//breadcrumb end

	$('#BirthDate').datepicker();
	$('#FirstName').watermark("First Name")
	$('#LastName').watermark("Last Name");

	$('#btnNo').click(function () {
		if ($("#add-driver").valid()) {
			$.post("/Information/Driver", $("#add-driver").serialize(), function (data) {
				window.location = "/Information/Contact/";
			}, "json");
		}
	});


	$('#btnYes').click(function () {

		if ($("#add-driver").valid()) {

			var FirstName = $('#FirstName').val();
			var LastName = $('#LastName').val();
			var BirthDate = $('#BirthDate').val();

			$.post("/Information/Driver", $("#add-driver").serialize(), function (data) {
				$('#section-drivers').append('<div id="driver-' + data.id + '" class="section-entry">' + FirstName + '  ' + LastName + '  ' + BirthDate + '<div style="float:right;"><a href="#" onclick="deleteDriver(' + data.id + ');" >Delete</a></div></div>');
				ClearValues();
			}, "json");
		}
	});

	$('#btnCancel').click(function () {
		window.location = "/Information/Contact/";
	});

});

function ClearValues() {
	$('#FirstName').val('');
	$('#LastName').val('');
	$('#Gender').val('');
	$('#MaritalStatus').val('');
	$('#BirthDate').val('');
	$('#Education').val('');
	$('#Occupation').val('');
}

function deleteDriver(id) {
	if (confirm('Are you sure you want to delete selected record(s)?')) {
		$.post("/Information/DeleteDriver", { driverId: id }, function (data) {
			if ($.trim(data.message) != "") {
				alert(data);
			}
			else {
				$('#driver-' + id).remove();
			}
		}, "json");
	}

}